<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>博客列表</title>
    <link rel="stylesheet" href="css/conmmon.css">
    <link rel="stylesheet" href="css/blog_list.css">
    <link rel="stylesheet" href="editor.md/css/editormd.min.css"/>
    <script src="js/jquery.min.js"></script>
    <script src="js/common.js"></script>
    <script src="editor.md/editormd.js"></script>
    <script src="editor.md/lib/marked.min.js"></script>
    <script src="editor.md/lib/prettify.min.js"></script>
</head>

<body>
<!-- 导航栏 -->
<div class="nav">
    <img src="img/logo2.jpg" alt="">
    <span class="title">博客系统</span>
    <!-- 用来占据中间位置 -->
    <span class="spacer"></span>
    <a href="blog_list.html">主页</a>
    <a href="blog_add.html">写博客</a>
    <!--    <a href="login.html">登陆</a>-->
    <a href="javascript:logout()">注销</a>
    <a href="about.html">站长简介</a>
</div>
<!-- 版心 -->
<div class="container">
    <!-- 左侧个人信息 -->
    <div class="container-left">
        <div class="card">
            <img src="img/default.jpg" class="avtar" alt="头像" id="photo">
            <h3 id="username"></h3>
            <h3 id="email"></h3>
            <div class="counter">
                <span>发布文章数量:</span> <span id="artCount"></span>
            </div>
            <a href="user_edit.html">编辑资料</a>
        </div>
    </div>
    <!-- 右侧内容详情 -->
    <div class="container-right" id="artDiv">

    </div>
</div>
</body>
<script>
    function showInfo() {
        jQuery.ajax({
            url: "/user/showinfo",
            type: "POST",
            data: {},
            success: function (result) {
                if (result != null && result.code == 200) {
                    jQuery("#username").text(result.data.username);
                    jQuery("#email").text(result.data.email);
                    jQuery("#artCount").text(result.data.artCount);
                    jQuery("#photo").src = result.data.photo;
                } else {
                    alert("个人信息加载失败，请刷新~")
                }
            }
        });
    }

    showInfo();

    function getMyArtList() {
        jQuery.ajax({
            url: "/article/myartlist",
            type: "POST",
            data: {},
            success: function (result) {
                if (result != null && result.code == 200) {
                    if (result.data != null && result.data.length > 0) {
                        var artListDiv = "";
                        for (var i = 0; i < result.data.length; i++) {
                            var artItem = result.data[i];
                            artListDiv += '<div class="blog">';
                            artListDiv += '<div class="title">' + artItem.title + '</div>';
                            artListDiv += '<div class="date"><span>更新时间:</span>' + artItem.updatetime + '&nbsp;&nbsp;<span>阅读量:</span>' + artItem.rcount + '</div>';
                            artListDiv += '<div class="desc">' + artItem.content + '</div>';
                            artListDiv += '<a href="blog_content.html?id=' +
                                artItem.id + '" class="detail">查看 &gt;&gt;</a>&nbsp;&nbsp;';
                            artListDiv += '<a href="blog_edit.html?id=' +
                                artItem.id + '" class="detail">修改 &gt;&gt;</a>&nbsp;&nbsp;';
                            artListDiv += '<a href="javascript:DelArt(' +
                                artItem.id + ');" class="detail">删除 &gt;&gt;</a>';
                            artListDiv += '</div>';
                        }
                        jQuery("#artDiv").html(artListDiv);
                    } else {
                        jQuery("#artDiv").html("<h3 style='text-align: center '>没有发布文章~快编辑发布文章</h3>")
                    }
                } else {
                    alert("文章列表获取失败，请刷新~");
                }
            }
        });
    }

    getMyArtList();

    function DelArt(id) {
        if (confirm("确实删除？")) {
            jQuery.ajax({
                url: "article/del",
                type: "POST",
                data: {"id": id},
                success: function (result) {
                    if (result != null && result.code == 200 && result.data == 1) {
                        alert("删除成功！");
                        // 刷新当前页面
                        location.href = location.href;
                    } else {
                        alert("删除失败，请重试！");
                    }
                }
            });
        }
    }
</script>
</html>